Skip to content

Exclude Stack from DOMServerStream#9896

Merged
gaearon merged 1 commit intofacebook:masterfrom
gaearon:no-stream-stack
Jun 8, 2017
Merged

Exclude Stack from DOMServerStream#9896
gaearon merged 1 commit intofacebook:masterfrom
gaearon:no-stream-stack

Conversation

@gaearon
Copy link
Copy Markdown
Collaborator

@gaearon gaearon commented Jun 8, 2017

I think the Stack-specific injection in DOMServerStream was unintentional.
It dragged the whole Stack implementation into it whereas we only need the separate DOM injection.

Tests pass, and the bundle got smaller.

@flarnie
Copy link
Copy Markdown
Contributor

flarnie commented Jun 8, 2017

This seems reasonable - I am digging a bit to see why ReactDOMStackInjection.inject(); was there. @spicyj or @tomocchino might know.

@flarnie
Copy link
Copy Markdown
Contributor

flarnie commented Jun 8, 2017

It seems like based on the comments in ReactDOMStackInjection it is intentional that it gets injected both in ReactDOM and ReactServerDOM, and this condition could have stopped it from creating duplicate code. I will need to read through all the associated modules to give a verdict on this I think.

@gaearon
Copy link
Copy Markdown
Collaborator Author

gaearon commented Jun 8, 2017

it is intentional that it gets injected both in ReactDOM and ReactServerDOM

Yes, because both ReactDOM and ReactDOMServer are Stack-based implementation. So they need to inject Stack-specific classes like ReactDOMComponent.

However ReactDOMServerStream (the one I’m looking at) does not use the Stack reconciler at all. So it doesn’t need to inject classes like ReactDOMComponent which are unused. The bloat its file size, but don’t actually end up being used.

this condition could have stopped it from creating duplicate code

The condition exists to prevent injecting twice when both ReactDOM and ReactDOMServer were used on the same page. It only mattered when we didn’t have flat bundles, as both ReactDOM and ReactDOMServer would use the same copy of the injection code. This condition isn’t useful now because both ReactDOM and ReactDOMServer ship with separate copies of this code. And regardless of that, we’re not using ReactDOM bundle anymore.

That said the condition would not have prevented the duplicate code. If a file is imported (like ReactDOMStackInjection is imported in ReactDOMServerStream), all its dependencies end up in the flat bundle, whether or not there is a boolean guard behind injection itself.

My point is that I think ReactDOMStackInjection is Stack-specific and has no effect for ReactDOMServerStream because it doesn’t use the Stack reconciler. So we end up pulling all the Stack code into a bundle that doesn’t use Stack. Since CI passed, I think this observation is correct: it was effectively dead code.

I am digging a bit to see why ReactDOMStackInjection.inject(); was there

I think most likely it was copypaste. Because the neighboring ReactDOMInjection.inject() was (and is) actually needed. I think Ben wrote that code before ReactDOMInjection and ReactStackDOMInjection were separated, and when rebasing it, Tom probably looked up a similar snippet in today’s ReactDOMServer, and thought both injections are necessary.

@gaearon
Copy link
Copy Markdown
Collaborator Author

gaearon commented Jun 8, 2017

I’ll get this in as it seems to work but can follow up if something’s missing.

@gaearon gaearon merged commit 6ab0531 into facebook:master Jun 8, 2017
@gaearon gaearon deleted the no-stream-stack branch June 8, 2017 18:41
@sophiebits
Copy link
Copy Markdown
Collaborator

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants